import { candidateGetInfoService, resumeGetsService } from '@/api/candidate'
import { defineStore } from 'pinia'
import { ref } from 'vue'
// 用户模块 token setToken removeToken

export const useCandidateStore = defineStore(
  'candidate',
  () => {
    /* token*/
    const token = ref('')
    const setToken = (newToken) => {
      token.value = newToken
    }
    const removeToken = () => {
      token.value = ''
    }
    /* candidate用户基本信息*/
    const candidate = ref({})
    const getCandidate = async () => {
      const name = candidate.value.username
      const res = await candidateGetInfoService({
        username: name
      }) //请求获取数据
      candidate.value = res.data.data
    }
    const setUsername = (username) => {
      candidate.value.username = username
    }
    const setCandidate = (obj) => {
      candidate.value = obj
    }
    /*简历列表 */
    let resumeList = ref([])
    const getResumeList = async () => {
      const name = candidate.value.username
      const res = await resumeGetsService({
        username: name
      })
      resumeList.value = res.data.data
      ElMessage({ type: 'success', message: '刷新成功' })
    }
    let setResumeList = (obj) => {
      resumeList.value = obj
    }
    return {
      token,
      setToken,
      removeToken,
      candidate,
      getCandidate,
      setCandidate,
      setUsername,
      resumeList,
      getResumeList,
      setResumeList
    }
  },
  {
    persist: true
  }
)
